#include "threadPool.h"
int tcpInit(const char *ip,const char *port,int *psockfd)
{
    // 创建套接字
    *psockfd = socket(AF_INET,SOCK_STREAM,0);
    // 端口可重复使用
    int reuse = 1;
    int ret = setsockopt(*psockfd,SOL_SOCKET,SO_REUSEADDR,&reuse,sizeof(reuse));
    ERROR_CHECK(ret,-1,"setsocketopt");
    // 初始化IP
    struct sockaddr_in server;
    server.sin_family = AF_INET;
    server.sin_port = htons(atoi(port));
    server.sin_addr.s_addr = inet_addr(ip);// 将点分十进制的ip转换为网络弟子
    ret = bind(*psockfd,(struct sockaddr *)&server,sizeof(server));
    ERROR_CHECK(ret,-1,"bind");
    // 监听：socket变为被动，其内部数据结构也发生变化，即接收和发送缓冲区变为半连接和全连接队列
    listen(*psockfd,50);
    return 0;
}
